home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume19 / flex2 / part01 next >
Encoding:
Internet Message Format  |  1989-06-21  |  54.7 KB

  1. Subject:  v19i055:  Flex, a fast LEX replacement, Part01/07
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Vern Paxson <vern@csam.lbl.gov>
  7. Posting-number: Volume 19, Issue 55
  8. Archive-name: flex2/part01
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 1 (of 7)."
  17. # Contents:  flex flex/COPYING flex/Changes flex/MISC flex/Makefile
  18. #   flex/README flex/ccl.c flex/ecs.c flex/scan.l flex/sym.c
  19. #   flex/yylex.c
  20. # Wrapped by rsalz@prune.bbn.com on Thu Jun 22 19:01:42 1989
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test ! -d 'flex' ; then
  23.     echo shar: Creating directory \"'flex'\"
  24.     mkdir 'flex'
  25. fi
  26. if test -f 'flex/COPYING' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'flex/COPYING'\"
  28. else
  29. echo shar: Extracting \"'flex/COPYING'\" \(1554 characters\)
  30. sed "s/^X//" >'flex/COPYING' <<'END_OF_FILE'
  31. XFlex carries the copyright used for BSD software, slightly modified
  32. Xbecause it originated at the Lawrence Berkeley (not Livermore!) Laboratory,
  33. Xwhich operates under a contract with the Department of Energy:
  34. X
  35. X    Copyright (c) 1989 The Regents of the University of California.
  36. X    All rights reserved.
  37. X
  38. X    This code is derived from software contributed to Berkeley by
  39. X    Vern Paxson.
  40. X
  41. X    The United States Government has rights in this work pursuant to
  42. X    contract no. DE-AC03-76SF00098 between the United States Department of
  43. X    Energy and the University of California.
  44. X
  45. X    Redistribution and use in source and binary forms are permitted
  46. X    provided that the above copyright notice and this paragraph are
  47. X    duplicated in all such forms and that any documentation,
  48. X    advertising materials, and other materials related to such
  49. X    distribution and use acknowledge that the software was developed
  50. X    by the University of California, Berkeley.  The name of the
  51. X    University may not be used to endorse or promote products derived
  52. X    from this software without specific prior written permission.
  53. X    THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  54. X    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  55. X    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  56. X
  57. XThis basically says "do whatever you please with this software except
  58. Xremove this notice".
  59. X
  60. XNote that the "flex.skel" scanner skeleton carries no copyright notice.
  61. XYou are free to do whatever you please with scanners generated using flex;
  62. Xfor them, you are not even bound by the above copyright.
  63. END_OF_FILE
  64. if test 1554 -ne `wc -c <'flex/COPYING'`; then
  65.     echo shar: \"'flex/COPYING'\" unpacked with wrong size!
  66. fi
  67. # end of 'flex/COPYING'
  68. fi
  69. if test -f 'flex/Changes' -a "${1}" != "-c" ; then 
  70.   echo shar: Will not clobber existing file \"'flex/Changes'\"
  71. else
  72. echo shar: Extracting \"'flex/Changes'\" \(3897 characters\)
  73. sed "s/^X//" >'flex/Changes' <<'END_OF_FILE'
  74. XChanges between 2.1 beta-test release of June '89 and previous release:
  75. X
  76. X    User-visible:
  77. X
  78. X    - -p flag generates a performance report to stderr.  The report
  79. X      consists of comments regarding features of the scanner rules
  80. X      which result in slower scanners.
  81. X
  82. X    - -b flag generates backtracking information to lex.backtrack.
  83. X      This is a list of scanner states which require backtracking
  84. X      and the characters on which they do so.  By adding rules
  85. X      one can remove backtracking states.  If all backtracking states
  86. X      are eliminated, the generated scanner will run faster.
  87. X      Backtracking is not yet documented in the manual entry.
  88. X
  89. X    - Variable trailing context now works, i.e., one can have
  90. X      rules like "(foo)*/[ \t]*bletch".  Some trailing context
  91. X      patterns still cannot be properly matched and generate
  92. X      error messages.  These are patterns where the ending of the
  93. X      first part of the rule matches the beginning of the second
  94. X      part, such as "zx*/xy*", where the 'x*' matches the 'x' at
  95. X      the beginning of the trailing context.  Lex won't get these
  96. X      patterns right either.
  97. X
  98. X    - Faster scanners.
  99. X
  100. X    - End-of-file rules.  The special rule "<<EOF>>" indicates
  101. X      actions which are to be taken when an end-of-file is
  102. X      encountered and yywrap() returns non-zero (i.e., indicates
  103. X      no further files to process).  See manual entry for example.
  104. X
  105. X    - The -r (reject used) flag is gone.  flex now scans the input
  106. X      for occurrences of the string "REJECT" to determine if the
  107. X      action is needed.  It tries to be intelligent about this but
  108. X      can be fooled.  One can force the presence or absence of
  109. X      REJECT by adding a line in the first section of the form
  110. X      "%used REJECT" or "%unused REJECT".
  111. X
  112. X    - yymore() has been implemented.  Similarly to REJECT, flex
  113. X      detects the use of yymore(), which can be overridden using
  114. X      "%used" or "%unused".
  115. X
  116. X    - Patterns like "x{0,3}" now work (i.e., with lower-limit == 0).
  117. X
  118. X    - Removed '\^x' for ctrl-x misfeature.
  119. X
  120. X    - Added '\a' and '\v' escape sequences.
  121. X
  122. X    - \<digits> now works for octal escape sequences; previously
  123. X      \0<digits> was required.
  124. X
  125. X    - Better error reporting; line numbers are associated with rules.
  126. X
  127. X    - yyleng is a macro; it cannot be accessed outside of the
  128. X      scanner source file.
  129. X
  130. X    - yytext and yyleng should not be modified within a flex action.
  131. X
  132. X    - Generated scanners #define the name FLEX_SCANNER.
  133. X
  134. X    - Rules are internally separated by YY_BREAK in lex.yy.c rather
  135. X      than break, to allow redefinition.
  136. X
  137. X    - The macro YY_USER_ACTION can be redefined to provide an action
  138. X      which is always executed prior to the matched rule's action.
  139. X    
  140. X    - yyrestart() is a new action which can be used to restart
  141. X      the scanner after it has seen an end-of-file (a "real" one,
  142. X      that is, one for which yywrap() returned non-zero).  It takes
  143. X      a FILE* argument indicating a new file to scan and sets
  144. X      things up so that a subsequent call to yylex() will start
  145. X      scanning that file.
  146. X
  147. X    - Internal scanner names all preceded by "yy_"
  148. X
  149. X    - lex.yy.c is deleted if errors are encountered during processing.
  150. X
  151. X    - Comments may be put in the first section of the input by preceding
  152. X      them with '#'.
  153. X
  154. X
  155. X
  156. X    Other changes:
  157. X
  158. X    - Some portability-related bugs fixed, in particular for machines
  159. X      with unsigned characters or sizeof( int* ) != sizeof( int ).
  160. X      Also, tweaks for VMS and Microsoft C (MS-DOS), and identifiers all
  161. X      trimmed to be 31 or fewer characters.  Shortened file names
  162. X      for dinosaur OS's.  Checks for allocating > 64K memory
  163. X      on 16 bit'ers.  Amiga tweaks.  Compiles using gcc on a Sun-3.
  164. X
  165. X    - Compressed and fast scanner skeletons merged.
  166. X
  167. X    - Skeleton header files done away with.
  168. X
  169. X    - Generated scanner uses prototypes and "const" for __STDC__.
  170. X
  171. X    - -DSV flag is now -DSYS_V for System V compilation.
  172. X
  173. X    - Removed all references to FTL language.
  174. X
  175. X    - Software now covered by BSD Copyright.
  176. X
  177. X    - flex will replace lex in subsequent BSD releases.
  178. END_OF_FILE
  179. if test 3897 -ne `wc -c <'flex/Changes'`; then
  180.     echo shar: \"'flex/Changes'\" unpacked with wrong size!
  181. fi
  182. # end of 'flex/Changes'
  183. fi
  184. if test -f 'flex/MISC' -a "${1}" != "-c" ; then 
  185.   echo shar: Will not clobber existing file \"'flex/MISC'\"
  186. else
  187. echo shar: Extracting \"'flex/MISC'\" \(7247 characters\)
  188. sed "s/^X//" >'flex/MISC' <<'END_OF_FILE'
  189. XMiscellaneous flex stuff.  In here you'll find an out-of-date VMS makefile
  190. Xfor flex and notes someone sent me regarding converting flex to deal with
  191. X8 bit characters.  This stuff is provided so that ambitious folks can pick
  192. Xit up and turn it into something viable.  I'd appreciate being sent any
  193. Xupdates resulting from work on this.
  194. X
  195. XThe makefile is from Fred Brehm (fwb@demon.siemens.com); the 8 bit chars
  196. Xfrom Earle Horton (arizona!earleh@eleazar.Dartmouth.EDU).
  197. X
  198. X
  199. X
  200. X############################ VMS MAKEFILE ##############################
  201. X
  202. X# VMS make file for "flex" tool
  203. X
  204. X# Redefine the following for your own environment
  205. XBIN = tools$$exe
  206. XLIB = tools$$library
  207. XINC = tools$$include
  208. XMAN = tools$$manual
  209. XLINKFLAGS = ,$(LIB):cc/opt
  210. X
  211. XSKELETON_FILE = "DEFAULT_SKELETON_FILE=""$(LIB):FLEX.SKEL"""
  212. XF_SKELETON_FILE = "FAST_SKELETON_FILE=""$(LIB):FLEX.FASTSKEL"""
  213. X
  214. XCCFLAGS = VMS
  215. XFLEX_FLAGS = -is
  216. X
  217. XFLEXOBJS = ccl.obj dfa.obj ecs.obj main.obj misc.obj nfa.obj parse.obj \
  218. Xscan.obj sym.obj tblcmp.obj yylex.obj
  219. X
  220. XOBJ = ccl.obj,dfa.obj,ecs.obj,main.obj,misc.obj,nfa.obj,parse.obj,\
  221. Xscan.obj,sym.obj,tblcmp.obj,yylex.obj
  222. X
  223. Xdefault : flex
  224. Xinstall : inc lib bin man
  225. Xinc : $(INC):flexskeldef.h $(INC):fastskeldef.h $(INC):flexskelcom.h
  226. Xlib : $(LIB):flex.skel $(LIB):flex.fastskel
  227. Xbin : $(BIN):flex
  228. X    flex :== $$ $(BIN):flex
  229. Xman : $(MAN):flex.doc
  230. X
  231. X$(INC):flexskeldef.h : flexskeldef.h
  232. X    copy flexskeldef.h $(INC)
  233. X$(INC):fastskeldef.h : fastskeldef.h
  234. X    copy fastskeldef.h $(INC)
  235. X$(INC):flexskelcom.h : flexskelcom.h
  236. X    copy flexskelcom.h $(INC)
  237. X$(LIB):flex.skel : flex.skel
  238. X    copy flex.skel $(LIB)
  239. X$(LIB):flex.fastskel : flex.fastskel
  240. X    copy flex.fastskel $(LIB)
  241. X$(BIN):flex.exe : flex.exe
  242. X    copy flex.exe $(BIN)
  243. X$(MAN):flex.doc : flex.doc
  244. X    copy flex.doc $(MAN)
  245. X
  246. Xflex : flex.exe
  247. X    flex :== $$ 'f$$environment("default")'flex
  248. X
  249. Xflex.exe : $(FLEXOBJS)
  250. X    link /exe=flex $(OBJ) $(LINKFLAGS)
  251. X
  252. Xparse.h : parse.c
  253. X
  254. Xparse.c : parse.y
  255. X    yacc :== $$ sys$$sysroot:[shellexe]yacc
  256. X    yacc -d parse.y
  257. X    copy y_tab.c parse.c
  258. X    copy y_tab.h parse.h
  259. X    del y_tab.h;*,y_tab.c;*
  260. X
  261. X#scan.c : scan.l
  262. X#    flex $(FLEX_FLAGS) scan.l
  263. X#    copy lex_yy.c scan.c
  264. X#    del lex_yy.c;*
  265. Xscan.c : scan.dist
  266. X    copy scan.dist scan.c
  267. X
  268. Xccl.obj : ccl.c flexdef.h
  269. X    cc /define=$(CCFLAGS) ccl.c
  270. Xdfa.obj : dfa.c flexdef.h
  271. X    cc /define=$(CCFLAGS) dfa.c
  272. Xecs.obj : ecs.c flexdef.h
  273. X    cc /define=$(CCFLAGS) ecs.c
  274. Xmain.obj : main.c flexdef.h
  275. X    cc /define=($(CCFLAGS),$(SKELETON_FILE),$(F_SKELETON_FILE)) main.c
  276. Xmisc.obj : misc.c flexdef.h
  277. X    cc /define=$(CCFLAGS) misc.c
  278. Xnfa.obj : nfa.c flexdef.h
  279. X    cc /define=$(CCFLAGS) nfa.c
  280. Xparse.obj : parse.c flexdef.h
  281. X    cc /define=$(CCFLAGS) parse.c
  282. Xscan.obj : scan.c parse.h flexdef.h
  283. X    cc /define=$(CCFLAGS) scan.c
  284. Xsym.obj : sym.c flexdef.h
  285. X    cc /define=$(CCFLAGS) sym.c
  286. Xtblcmp.obj : tblcmp.c flexdef.h
  287. X    cc /define=$(CCFLAGS) tblcmp.c
  288. Xyylex.obj : yylex.c parse.h flexdef.h
  289. X    cc /define=$(CCFLAGS) yylex.c
  290. X
  291. Xclean :
  292. X    del flex.exe;*
  293. X    del scan.c;*
  294. X    del parse.c;*
  295. X    del parse.h;*
  296. X    del lex_yy.c;*
  297. X    del *.obj;*
  298. X    del flex*.tmp;*
  299. X    del *.diff;*
  300. X    del y_tab.*;*
  301. X    del makefile.;*
  302. X    purge/log
  303. X    copy makefile.vms makefile.
  304. X
  305. Xmakefile : makefile.vms
  306. X    copy makefile.vms makefile.
  307. X
  308. Xtest : flex
  309. X    define tools$$lib 'f$$environment("default")'
  310. X    flex $(FLEX_FLAGS) scan.l
  311. X    define tools$$lib tools$$sys:[lib]
  312. X    diff/out=flex.diff scan.dist lex_yy.c
  313. X    type/page flex.diff
  314. X
  315. X
  316. X
  317. X######################### Stuff for 8 Bit chars ########################
  318. X
  319. X
  320. XEarle Horton has made a version of flex run on the MacIntosh under MPW.  Not
  321. Xbeing content to scan regular ascii, he deals with all 8 bits.  I also have
  322. Xwanted to write VMS filters that recognize <CSI>, etc. so I contacted him
  323. Xabout his work.  He seems to be unable to reach you directly--the rest of
  324. Xthis is his note...
  325. X---------------------------Note from Earle------------------
  326. X>From arizona!earleh@eleazar.Dartmouth.EDU Fri May 27 11:33:09 1988
  327. XReceived: from DARTVAX.DARTMOUTH.EDU by megaron.arizona.edu; Fri, 27 May 88 10:55:39 MST
  328. XReceived: from eleazar.dartmouth.edu by dartvax.dartmouth.edu (5.59/3.4ROOT)
  329. X    id AA17044; Fri, 27 May 88 13:53:18 EDT
  330. XReceived: by eleazar.dartmouth.edu (5.59/3.2LEAF)
  331. X    id AA15906; Fri, 27 May 88 13:53:04 EDT
  332. XDate: Fri, 27 May 88 13:53:04 EDT
  333. XFrom: arizona!earleh@eleazar.Dartmouth.EDU (Earle R. Horton)
  334. XMessage-Id: <8805271753.AA15906@eleazar.dartmouth.edu>
  335. XTo: eleazar!earleh, earleh@eleazar.Dartmouth.EDU, naucse!jdc
  336. XSubject: Re: Flex and DEC multi-nationals, help!
  337. XStatus: R
  338. X
  339. XJohn,
  340. X
  341. X     I have posted the diffs to comp.sources.unix, and I think that
  342. Xthey could be used to generate a VAX C version which scans DEC
  343. Xmulti-nationals with little extra effort.  I tried the address which
  344. Xyou give for Vern several times, only to have it bounce back to me for
  345. Xsome mysterious reason known only to a mail daemon somewhere.  I would
  346. Xindeed appreciate it if you could forward this to him.
  347. X
  348. X     I have found that the full internal representation of all
  349. Xcharacters as shorts is not necessary.  Rather, it is only necessary to
  350. X
  351. X     a)  Prevent conversion of valid characters to negative ints.  I
  352. X         do this with a mask, defined for the Mac and UNIX as 
  353. X         "#define BYTEMASK 0xFF".  Any time a char is converted to an
  354. X         int, AND it with the mask.  Then you don't have to declare
  355. X         chars as unsigned chars, which is tiresome.
  356. X
  357. X     b)  The routine mkeccl() uses negation of characters for a flag
  358. X         to determine whether they have been processed.  I used a
  359. X         debugger to estimate how many times this routine is actually
  360. X         called when Flex scans scan.l.  Based on what this looked
  361. X         like to me, I decided that it would be appropriate to have
  362. X         only the routine mkeccl() use an array of shorts for its
  363. X         internal processing.  When mkeccl() is called, it gets a
  364. X         pointer to an array of shorts using alloca(), and then reads
  365. X         the characters which it is to process into this array using
  366. X         the method in (a).  When mkeccl() is done, the shorts are put
  367. X         back into chars, and things proceed.  The internal processing
  368. X         done by mkeccl() is the same.
  369. X
  370. X     Flex compiled with these changes correctly scans all characters
  371. Xin the Macintosh character set, to the best of my ability to test it.
  372. XIn addition, it correctly scans chars with values > 127 on a UNIX VAX!
  373. XContrary to "common knowledge", text files which exist on a UNIX
  374. Xmachine may have valid characters in the range [\0177-\0377].  An
  375. Xexample is if I want to write a program to run on a UNIX machine which
  376. Xconverts German characters to ASCII.  The ess-tset (I believe that is
  377. Xthe name) can be converted to "ss" with little loss of sense in most cases.
  378. X         
  379. X     The only question I have about my procedure is that it looks
  380. Xexpensive to convert the ccltbl array to shorts and back every time
  381. Xmkeccl() is called.  However, the routine is not called an inordinately
  382. Xlarge number of times, and this conversion is probably not more
  383. Xexpensive than a couple of calls to strcpy(), for instance.  To
  384. Xdetermine whether this is the most efficient method, one would have to
  385. Xgo through the effort to convert Flex to use shorts for all internal
  386. Xrepresentation, then profile the two methods.  Not my idea of a good
  387. Xtime.
  388. X
  389. X     Flex is a real nice program.  I couldn't find anything else wrong
  390. Xwith it.
  391. X
  392. XEarle Horton
  393. X
  394. X
  395. END_OF_FILE
  396. if test 7247 -ne `wc -c <'flex/MISC'`; then
  397.     echo shar: \"'flex/MISC'\" unpacked with wrong size!
  398. fi
  399. # end of 'flex/MISC'
  400. fi
  401. if test -f 'flex/Makefile' -a "${1}" != "-c" ; then 
  402.   echo shar: Will not clobber existing file \"'flex/Makefile'\"
  403. else
  404. echo shar: Extracting \"'flex/Makefile'\" \(1900 characters\)
  405. sed "s/^X//" >'flex/Makefile' <<'END_OF_FILE'
  406. X# make file for "flex" tool
  407. X
  408. X# @(#) $Header: Makefile,v 2.3 89/06/20 17:27:12 vern Exp $ (LBL)
  409. X
  410. X# Porting considerations:
  411. X#
  412. X#    For System V Unix machines, add -DSYS_V to CFLAGS.
  413. X#    For Vax/VMS, add -DSYS_V to CFLAGS.
  414. X#    For MS-DOS, add "-DMS_DOS -DSYS_V" to CFLAGS.  Create \tmp if not present.
  415. X#         You will also want to rename flex.skel to something with a three
  416. X#         character extension, change SKELETON_FILE below appropriately,
  417. X#    For Amiga, add "-DAMIGA -DSYS_V" to CFLAGS.
  418. X#
  419. X# A long time ago, flex was successfully built using Microsoft C and
  420. X# the following options: /AL, /stack:10000, -LARGE, -Ml, -Mt128, -DSYS_V
  421. X
  422. X
  423. X# the first time around use "make first_flex"
  424. X
  425. X
  426. XSKELETON_DIR = /usr/local/lib
  427. XSKELETON_FILE = flex.skel
  428. XSKELFLAGS = -DDEFAULT_SKELETON_FILE=\"$(SKELETON_DIR)/$(SKELETON_FILE)\"
  429. XCFLAGS = -O
  430. XLDFLAGS = -s
  431. X
  432. XFLEX_FLAGS =
  433. XFLEX = ./flex
  434. XCC = cc
  435. X
  436. XFLEXOBJS = \
  437. X    ccl.o \
  438. X    dfa.o \
  439. X    ecs.o \
  440. X    gen.o \
  441. X    main.o \
  442. X    misc.o \
  443. X    nfa.o \
  444. X    parse.o \
  445. X    scan.o \
  446. X    sym.o \
  447. X    tblcmp.o \
  448. X    yylex.o
  449. X
  450. XFLEX_C_SOURCES = \
  451. X    ccl.c \
  452. X    dfa.c \
  453. X    ecs.c \
  454. X    gen.c \
  455. X    main.c \
  456. X    misc.c \
  457. X    nfa.c \
  458. X    parse.c \
  459. X    scan.c \
  460. X    sym.c \
  461. X    tblcmp.c \
  462. X    yylex.c
  463. X
  464. Xflex : $(FLEXOBJS)
  465. X    $(CC) $(CFLAGS) -o flex $(LDFLAGS) $(FLEXOBJS)
  466. X
  467. Xfirst_flex:
  468. X    cp initscan.c scan.c
  469. X    make $(MFLAGS) flex
  470. X
  471. Xparse.h parse.c : parse.y
  472. X    $(YACC) -d parse.y
  473. X    @mv y.tab.c parse.c
  474. X    @mv y.tab.h parse.h
  475. X
  476. Xscan.c : scan.l
  477. X    $(FLEX) -ist $(FLEX_FLAGS) scan.l >scan.c
  478. X
  479. Xscan.o : scan.c parse.h
  480. X
  481. Xmain.o : main.c
  482. X    $(CC) $(CFLAGS) -c $(SKELFLAGS) main.c
  483. X
  484. Xflex.man : flex.1
  485. X    nroff -man flex.1 >flex.man
  486. X
  487. Xlint : $(FLEX_C_SOURCES)
  488. X    lint $(FLEX_C_SOURCES) > flex.lint
  489. X
  490. Xdistrib :
  491. X    mv scan.c initscan.c
  492. X    chmod 444 initscan.c
  493. X    $(MAKE) $(MFLAGS) clean
  494. X
  495. Xclean :
  496. X    rm -f core errs flex *.o parse.c *.lint parse.h flex.man tags
  497. X
  498. Xtags :
  499. X    ctags $(FLEX_C_SOURCES)
  500. X
  501. Xvms :    flex.man
  502. X    $(MAKE) $(MFLAGS) distrib
  503. X
  504. Xtest :
  505. X    $(FLEX) -ist $(FLEX_FLAGS) scan.l | diff scan.c -
  506. END_OF_FILE
  507. if test 1900 -ne `wc -c <'flex/Makefile'`; then
  508.     echo shar: \"'flex/Makefile'\" unpacked with wrong size!
  509. fi
  510. # end of 'flex/Makefile'
  511. fi
  512. if test -f 'flex/README' -a "${1}" != "-c" ; then 
  513.   echo shar: Will not clobber existing file \"'flex/README'\"
  514. else
  515. echo shar: Extracting \"'flex/README'\" \(2472 characters\)
  516. sed "s/^X//" >'flex/README' <<'END_OF_FILE'
  517. X// $Header: README,v 2.4 89/06/20 17:12:01 vern Exp $
  518. X
  519. XThis is release 2.1 of flex - a beta release.
  520. X
  521. XThe flex distribution consists of the following files:
  522. X
  523. X    README        This message
  524. X
  525. X    Makefile
  526. X    flexdef.h
  527. X    parse.y
  528. X    scan.l
  529. X    ccl.c
  530. X    dfa.c
  531. X    ecs.c        flex sources
  532. X    gen.c
  533. X    main.c
  534. X    misc.c
  535. X    nfa.c
  536. X    sym.c
  537. X    tblcmp.c
  538. X    yylex.c
  539. X
  540. X    initscan.c    pre-flex'd version of scan.l
  541. X
  542. X    flex.skel    skeleton for generated scanners
  543. X
  544. X    flex.1        manual entry
  545. X
  546. X    Changes        Differences between this release and the previous one
  547. X    COPYING        flex's copyright
  548. X    MISC        miscellaneous stuff (e.g., old VMS Makefile) which
  549. X            almost no one will care about
  550. X
  551. X
  552. XIf you have installed a previous version of flex, delete it (after making
  553. Xbackups, of course).  This will entail removing the source directory,
  554. X/usr/include/{flexskelcom,fastskeldef,flexskeldef}.h, and
  555. X/usr/local/lib/flex.{skel,fastskel}, if that's where you put the various
  556. Xpieces.
  557. X
  558. X
  559. XDecide where you want to keep flex.skel (suggestion:  /usr/local/lib) and
  560. Xmove it there.  Edit "Makefile" and change the definition of SKELETON_FILE
  561. Xto reflect the full pathname of flex.skel.
  562. X
  563. XRead the "Porting considerations" note in the Makefile and make
  564. Xthe necessary changes.
  565. X
  566. X
  567. XTo make flex for the first time, use:
  568. X
  569. X    make first_flex
  570. X
  571. Xwhich uses the pre-generated copy of the flex scanner (the scanner
  572. Xitself is written using flex).
  573. X
  574. XAssuming it builds successfully, you can test it using
  575. X
  576. X    make test
  577. X
  578. XThe "diff" should not show any differences.
  579. X
  580. XIf you're feeling adventurous, rebuild scan.c using various
  581. Xcombinations of FLEX_FLAGS, each time trying "make test" when
  582. Xyou're done.  To rebuild it, do
  583. X
  584. X    rm scan.c
  585. X    make FLEX_FLAGS="..."
  586. X
  587. Xwhere "..." is one of:
  588. X
  589. X    -c
  590. X    -ce
  591. X    -cm
  592. X    -cfe
  593. X    -cFe
  594. X
  595. Xand testing using:
  596. X
  597. X    make FLEX_FLAGS="..." test
  598. X
  599. X
  600. XFormat the manual entry using
  601. X
  602. X    make flex.man
  603. X
  604. X
  605. XPlease send problems and feedback to:
  606. X
  607. X    vern@{csam.lbl.gov,rtsg.ee.lbl.gov}  or  ucbvax!csam.lbl.gov!vern
  608. X
  609. X    Vern Paxson
  610. X    Real Time Systems
  611. X    Bldg. 46A
  612. X    Lawrence Berkeley Laboratory
  613. X    1 Cyclotron Rd.
  614. X    Berkeley, CA 94720
  615. X
  616. X    (415) 486-6411
  617. X
  618. X
  619. XI will be gone from mid-July '89 through mid-August '89.  From August on,
  620. Xthe addresses are:
  621. X
  622. X    vern@cs.cornell.edu    (email sent to the former addresses should
  623. X                 continue to be forwarded for quite a while)
  624. X                (if I'm unlucky, you'll have to send mail
  625. X                 to "paxson@cs.cornell.edu", so try that if
  626. X                 the first doesn't work)
  627. X
  628. X    Vern Paxson
  629. X    CS Department
  630. X    Grad Office
  631. X    4126 Upson
  632. X    Cornell University
  633. X    Ithaca, NY 14853-7501
  634. X
  635. X    <no phone number yet>
  636. END_OF_FILE
  637. if test 2472 -ne `wc -c <'flex/README'`; then
  638.     echo shar: \"'flex/README'\" unpacked with wrong size!
  639. fi
  640. # end of 'flex/README'
  641. fi
  642. if test -f 'flex/ccl.c' -a "${1}" != "-c" ; then 
  643.   echo shar: Will not clobber existing file \"'flex/ccl.c'\"
  644. else
  645. echo shar: Extracting \"'flex/ccl.c'\" \(4067 characters\)
  646. sed "s/^X//" >'flex/ccl.c' <<'END_OF_FILE'
  647. X/* ccl - routines for character classes */
  648. X
  649. X/*
  650. X * Copyright (c) 1989 The Regents of the University of California.
  651. X * All rights reserved.
  652. X *
  653. X * This code is derived from software contributed to Berkeley by
  654. X * Vern Paxson.
  655. X * 
  656. X * The United States Government has rights in this work pursuant to
  657. X * contract no. DE-AC03-76SF00098 between the United States Department of
  658. X * Energy and the University of California.
  659. X *
  660. X * Redistribution and use in source and binary forms are permitted
  661. X * provided that the above copyright notice and this paragraph are
  662. X * duplicated in all such forms and that any documentation,
  663. X * advertising materials, and other materials related to such
  664. X * distribution and use acknowledge that the software was developed
  665. X * by the University of California, Berkeley.  The name of the
  666. X * University may not be used to endorse or promote products derived
  667. X * from this software without specific prior written permission.
  668. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  669. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  670. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  671. X */
  672. X
  673. X#ifndef lint
  674. X
  675. Xstatic char copyright[] =
  676. X    "@(#) Copyright (c) 1989 The Regents of the University of California.\n";
  677. Xstatic char CR_continuation[] = "@(#) All rights reserved.\n";
  678. X
  679. Xstatic char rcsid[] =
  680. X    "@(#) $Header: ccl.c,v 2.0 89/06/20 15:49:07 vern Locked $ (LBL)";
  681. X
  682. X#endif
  683. X
  684. X#include "flexdef.h"
  685. X
  686. X/* ccladd - add a single character to a ccl
  687. X *
  688. X * synopsis
  689. X *    int cclp;
  690. X *    char ch;
  691. X *    ccladd( cclp, ch );
  692. X */
  693. X
  694. Xccladd( cclp, ch )
  695. Xint cclp;
  696. Xchar ch;
  697. X
  698. X    {
  699. X    int ind, len, newpos, i;
  700. X
  701. X    len = ccllen[cclp];
  702. X    ind = cclmap[cclp];
  703. X
  704. X    /* check to see if the character is already in the ccl */
  705. X
  706. X    for ( i = 0; i < len; ++i )
  707. X    if ( ccltbl[ind + i] == ch )
  708. X        return;
  709. X
  710. X    newpos = ind + len;
  711. X
  712. X    if ( newpos >= current_max_ccl_tbl_size )
  713. X    {
  714. X    current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT;
  715. X
  716. X    ++num_reallocs;
  717. X
  718. X    ccltbl = reallocate_character_array( ccltbl, current_max_ccl_tbl_size );
  719. X    }
  720. X
  721. X    ccllen[cclp] = len + 1;
  722. X    ccltbl[newpos] = ch;
  723. X    }
  724. X
  725. X
  726. X/* cclinit - make an empty ccl
  727. X *
  728. X * synopsis
  729. X *    int cclinit();
  730. X *    new_ccl = cclinit();
  731. X */
  732. X
  733. Xint cclinit()
  734. X
  735. X    {
  736. X    if ( ++lastccl >= current_maxccls )
  737. X    {
  738. X    current_maxccls += MAX_CCLS_INCREMENT;
  739. X
  740. X    ++num_reallocs;
  741. X
  742. X    cclmap = reallocate_integer_array( cclmap, current_maxccls );
  743. X    ccllen = reallocate_integer_array( ccllen, current_maxccls );
  744. X    cclng = reallocate_integer_array( cclng, current_maxccls );
  745. X    }
  746. X
  747. X    if ( lastccl == 1 )
  748. X    /* we're making the first ccl */
  749. X    cclmap[lastccl] = 0;
  750. X
  751. X    else
  752. X    /* the new pointer is just past the end of the last ccl.  Since
  753. X     * the cclmap points to the \first/ character of a ccl, adding the
  754. X     * length of the ccl to the cclmap pointer will produce a cursor
  755. X     * to the first free space
  756. X     */
  757. X    cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1];
  758. X
  759. X    ccllen[lastccl] = 0;
  760. X    cclng[lastccl] = 0;    /* ccl's start out life un-negated */
  761. X
  762. X    return ( lastccl );
  763. X    }
  764. X
  765. X
  766. X/* cclnegate - negate a ccl
  767. X *
  768. X * synopsis
  769. X *    int cclp;
  770. X *    cclnegate( ccl );
  771. X */
  772. X
  773. Xcclnegate( cclp )
  774. Xint cclp;
  775. X
  776. X    {
  777. X    cclng[cclp] = 1;
  778. X    }
  779. X
  780. X
  781. X/* list_character_set - list the members of a set of characters in CCL form
  782. X *
  783. X * synopsis
  784. X *     int cset[CSIZE + 1];
  785. X *     FILE *file;
  786. X *     list_character_set( cset );
  787. X *
  788. X * writes to the given file a character-class representation of those
  789. X * characters present in the given set.  A character is present if it
  790. X * has a non-zero value in the set array.
  791. X */
  792. X
  793. Xlist_character_set( file, cset )
  794. XFILE *file;
  795. Xint cset[];
  796. X
  797. X    {
  798. X    register int i;
  799. X    char *readable_form();
  800. X
  801. X    putc( '[', file );
  802. X
  803. X    for ( i = 1; i <= CSIZE; ++i )
  804. X    {
  805. X    if ( cset[i] )
  806. X        {
  807. X        register int start_char = i;
  808. X
  809. X        putc( ' ', file );
  810. X
  811. X        fputs( readable_form( i ), file );
  812. X
  813. X        while ( ++i <= CSIZE && cset[i] )
  814. X        ;
  815. X
  816. X        if ( i - 1 > start_char )
  817. X        /* this was a run */
  818. X        fprintf( file, "-%s", readable_form( i - 1 ) );
  819. X
  820. X        putc( ' ', file );
  821. X        }
  822. X    }
  823. X
  824. X    putc( ']', file );
  825. X    }
  826. END_OF_FILE
  827. if test 4067 -ne `wc -c <'flex/ccl.c'`; then
  828.     echo shar: \"'flex/ccl.c'\" unpacked with wrong size!
  829. fi
  830. # end of 'flex/ccl.c'
  831. fi
  832. if test -f 'flex/ecs.c' -a "${1}" != "-c" ; then 
  833.   echo shar: Will not clobber existing file \"'flex/ecs.c'\"
  834. else
  835. echo shar: Extracting \"'flex/ecs.c'\" \(5548 characters\)
  836. sed "s/^X//" >'flex/ecs.c' <<'END_OF_FILE'
  837. X/* ecs - equivalence class routines */
  838. X
  839. X/*
  840. X * Copyright (c) 1989 The Regents of the University of California.
  841. X * All rights reserved.
  842. X *
  843. X * This code is derived from software contributed to Berkeley by
  844. X * Vern Paxson.
  845. X * 
  846. X * The United States Government has rights in this work pursuant to
  847. X * contract no. DE-AC03-76SF00098 between the United States Department of
  848. X * Energy and the University of California.
  849. X *
  850. X * Redistribution and use in source and binary forms are permitted
  851. X * provided that the above copyright notice and this paragraph are
  852. X * duplicated in all such forms and that any documentation,
  853. X * advertising materials, and other materials related to such
  854. X * distribution and use acknowledge that the software was developed
  855. X * by the University of California, Berkeley.  The name of the
  856. X * University may not be used to endorse or promote products derived
  857. X * from this software without specific prior written permission.
  858. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  859. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  860. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  861. X */
  862. X
  863. X#ifndef lint
  864. X
  865. Xstatic char copyright[] =
  866. X    "@(#) Copyright (c) 1989 The Regents of the University of California.\n";
  867. Xstatic char CR_continuation[] = "@(#) All rights reserved.\n";
  868. X
  869. Xstatic char rcsid[] =
  870. X    "@(#) $Header: ecs.c,v 2.0 89/06/20 15:49:39 vern Locked $ (LBL)";
  871. X
  872. X#endif
  873. X
  874. X#include "flexdef.h"
  875. X
  876. X/* ccl2ecl - convert character classes to set of equivalence classes
  877. X *
  878. X * synopsis
  879. X *    ccl2ecl();
  880. X */
  881. X
  882. Xccl2ecl()
  883. X
  884. X    {
  885. X    int i, ich, newlen, cclp, ccls, cclmec;
  886. X
  887. X    for ( i = 1; i <= lastccl; ++i )
  888. X    {
  889. X    /* we loop through each character class, and for each character
  890. X     * in the class, add the character's equivalence class to the
  891. X     * new "character" class we are creating.  Thus when we are all
  892. X     * done, character classes will really consist of collections
  893. X     * of equivalence classes
  894. X     */
  895. X
  896. X    newlen = 0;
  897. X    cclp = cclmap[i];
  898. X
  899. X    for ( ccls = 0; ccls < ccllen[i]; ++ccls )
  900. X        {
  901. X        ich = ccltbl[cclp + ccls];
  902. X        cclmec = ecgroup[ich];
  903. X        if ( cclmec > 0 )
  904. X        {
  905. X        ccltbl[cclp + newlen] = cclmec;
  906. X        ++newlen;
  907. X        }
  908. X        }
  909. X
  910. X    ccllen[i] = newlen;
  911. X    }
  912. X    }
  913. X
  914. X
  915. X/* cre8ecs - associate equivalence class numbers with class members
  916. X *
  917. X * synopsis
  918. X *    int cre8ecs();
  919. X *    number of classes = cre8ecs( fwd, bck, num );
  920. X *
  921. X *  fwd is the forward linked-list of equivalence class members.  bck
  922. X *  is the backward linked-list, and num is the number of class members.
  923. X *  Returned is the number of classes.
  924. X */
  925. X
  926. Xint cre8ecs( fwd, bck, num )
  927. Xint fwd[], bck[], num;
  928. X
  929. X    {
  930. X    int i, j, numcl;
  931. X
  932. X    numcl = 0;
  933. X
  934. X    /* create equivalence class numbers.  From now on, abs( bck(x) )
  935. X     * is the equivalence class number for object x.  If bck(x)
  936. X     * is positive, then x is the representative of its equivalence
  937. X     * class.
  938. X     */
  939. X
  940. X    for ( i = 1; i <= num; ++i )
  941. X    if ( bck[i] == NIL )
  942. X        {
  943. X        bck[i] = ++numcl;
  944. X        for ( j = fwd[i]; j != NIL; j = fwd[j] )
  945. X        bck[j] = -numcl;
  946. X        }
  947. X
  948. X    return ( numcl );
  949. X    }
  950. X
  951. X
  952. X/* mkeccl - update equivalence classes based on character class xtions
  953. X *
  954. X * synopsis
  955. X *    char ccls[];
  956. X *    int lenccl, fwd[llsiz], bck[llsiz], llsiz;
  957. X *    mkeccl( ccls, lenccl, fwd, bck, llsiz );
  958. X *
  959. X * where ccls contains the elements of the character class, lenccl is the
  960. X * number of elements in the ccl, fwd is the forward link-list of equivalent
  961. X * characters, bck is the backward link-list, and llsiz size of the link-list
  962. X */
  963. X
  964. Xmkeccl( ccls, lenccl, fwd, bck, llsiz )
  965. Xchar ccls[];
  966. Xint lenccl, fwd[], bck[], llsiz;
  967. X
  968. X    {
  969. X    int cclp, oldec, newec;
  970. X    int cclm, i, j;
  971. X
  972. X#define PROCFLG 0x80
  973. X
  974. X    /* note that it doesn't matter whether or not the character class is
  975. X     * negated.  The same results will be obtained in either case.
  976. X     */
  977. X
  978. X    cclp = 0;
  979. X
  980. X    while ( cclp < lenccl )
  981. X    {
  982. X    cclm = ccls[cclp];
  983. X    oldec = bck[cclm];
  984. X    newec = cclm;
  985. X
  986. X    j = cclp + 1;
  987. X
  988. X    for ( i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i] )
  989. X        { /* look for the symbol in the character class */
  990. X        for ( ; j < lenccl && (ccls[j] <= i || (ccls[j] & PROCFLG)); ++j )
  991. X        if ( ccls[j] == i )
  992. X            {
  993. X            /* we found an old companion of cclm in the ccl.
  994. X             * link it into the new equivalence class and flag it as
  995. X             * having been processed
  996. X             */
  997. X
  998. X            bck[i] = newec;
  999. X            fwd[newec] = i;
  1000. X            newec = i;
  1001. X            ccls[j] |= PROCFLG;    /* set flag so we don't reprocess */
  1002. X
  1003. X            /* get next equivalence class member */
  1004. X            /* continue 2 */
  1005. X            goto next_pt;
  1006. X            }
  1007. X
  1008. X        /* symbol isn't in character class.  Put it in the old equivalence
  1009. X         * class
  1010. X         */
  1011. X
  1012. X        bck[i] = oldec;
  1013. X
  1014. X        if ( oldec != NIL )
  1015. X        fwd[oldec] = i;
  1016. X
  1017. X        oldec = i;
  1018. Xnext_pt:
  1019. X        ;
  1020. X        }
  1021. X
  1022. X    if ( bck[cclm] != NIL || oldec != bck[cclm] )
  1023. X        {
  1024. X        bck[cclm] = NIL;
  1025. X        fwd[oldec] = NIL;
  1026. X        }
  1027. X
  1028. X    fwd[newec] = NIL;
  1029. X
  1030. X    /* find next ccl member to process */
  1031. X
  1032. X    for ( ++cclp; (ccls[cclp] & PROCFLG) && cclp < lenccl; ++cclp )
  1033. X        {
  1034. X        /* reset "doesn't need processing" flag */
  1035. X        ccls[cclp] &= ~PROCFLG;
  1036. X        }
  1037. X    }
  1038. X    }
  1039. X
  1040. X
  1041. X/* mkechar - create equivalence class for single character
  1042. X *
  1043. X * synopsis
  1044. X *    int tch, fwd[], bck[];
  1045. X *    mkechar( tch, fwd, bck );
  1046. X */
  1047. X
  1048. Xmkechar( tch, fwd, bck )
  1049. Xint tch, fwd[], bck[];
  1050. X
  1051. X    {
  1052. X    /* if until now the character has been a proper subset of
  1053. X     * an equivalence class, break it away to create a new ec
  1054. X     */
  1055. X
  1056. X    if ( fwd[tch] != NIL )
  1057. X    bck[fwd[tch]] = bck[tch];
  1058. X
  1059. X    if ( bck[tch] != NIL )
  1060. X    fwd[bck[tch]] = fwd[tch];
  1061. X
  1062. X    fwd[tch] = NIL;
  1063. X    bck[tch] = NIL;
  1064. X    }
  1065. END_OF_FILE
  1066. if test 5548 -ne `wc -c <'flex/ecs.c'`; then
  1067.     echo shar: \"'flex/ecs.c'\" unpacked with wrong size!
  1068. fi
  1069. # end of 'flex/ecs.c'
  1070. fi
  1071. if test -f 'flex/scan.l' -a "${1}" != "-c" ; then 
  1072.   echo shar: Will not clobber existing file \"'flex/scan.l'\"
  1073. else
  1074. echo shar: Extracting \"'flex/scan.l'\" \(10686 characters\)
  1075. sed "s/^X//" >'flex/scan.l' <<'END_OF_FILE'
  1076. X/* scan.l - scanner for flex input */
  1077. X
  1078. X/*
  1079. X * Copyright (c) 1989 The Regents of the University of California.
  1080. X * All rights reserved.
  1081. X *
  1082. X * This code is derived from software contributed to Berkeley by
  1083. X * Vern Paxson.
  1084. X * 
  1085. X * The United States Government has rights in this work pursuant to
  1086. X * contract no. DE-AC03-76SF00098 between the United States Department of
  1087. X * Energy and the University of California.
  1088. X *
  1089. X * Redistribution and use in source and binary forms are permitted
  1090. X * provided that the above copyright notice and this paragraph are
  1091. X * duplicated in all such forms and that any documentation,
  1092. X * advertising materials, and other materials related to such
  1093. X * distribution and use acknowledge that the software was developed
  1094. X * by the University of California, Berkeley.  The name of the
  1095. X * University may not be used to endorse or promote products derived
  1096. X * from this software without specific prior written permission.
  1097. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1098. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1099. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1100. X */
  1101. X
  1102. X%{
  1103. X#include "flexdef.h"
  1104. X#include "parse.h"
  1105. X
  1106. X#ifndef lint
  1107. Xstatic char copyright[] =
  1108. X    "@(#) Copyright (c) 1989 The Regents of the University of California.\n";
  1109. Xstatic char CR_continuation[] = "@(#) All rights reserved.\n";
  1110. X
  1111. Xstatic char rcsid[] =
  1112. X    "@(#) $Header: scan.l,v 2.1 89/06/20 17:24:13 vern Exp $ (LBL)";
  1113. X#endif
  1114. X
  1115. X#define ACTION_ECHO fprintf( temp_action_file, "%s", yytext )
  1116. X#define MARK_END_OF_PROLOG fprintf( temp_action_file, "%%%% end of prolog\n" );
  1117. X
  1118. X#undef YY_DECL
  1119. X#define YY_DECL \
  1120. X    int flexscan()
  1121. X
  1122. X#define RETURNCHAR \
  1123. X    yylval = yytext[0]; \
  1124. X    return ( CHAR );
  1125. X
  1126. X#define RETURNNAME \
  1127. X    (void) strcpy( nmstr, yytext ); \
  1128. X    return ( NAME );
  1129. X
  1130. X#define PUT_BACK_STRING(str, start) \
  1131. X    for ( i = strlen( str ) - 1; i >= start; --i ) \
  1132. X        unput(str[i])
  1133. X
  1134. X#define CHECK_REJECT(str) \
  1135. X    if ( all_upper( str ) ) \
  1136. X        reject = true;
  1137. X
  1138. X#define CHECK_YYMORE(str) \
  1139. X    if ( all_lower( str ) ) \
  1140. X        yymore_used = true;
  1141. X%}
  1142. X
  1143. X%x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
  1144. X%x FIRSTCCL CCL ACTION RECOVER BRACEERROR C_COMMENT C_COMMENT_2 ACTION_COMMENT
  1145. X%x ACTION_STRING PERCENT_BRACE_ACTION USED_LIST
  1146. X
  1147. XWS        [ \t\f]+
  1148. XOPTWS        [ \t\f]*
  1149. XNOT_WS        [^ \t\f\n]
  1150. X
  1151. XNAME        [a-z_][a-z_0-9-]*
  1152. XNOT_NAME    [^a-z_\n]+
  1153. X
  1154. XSCNAME        {NAME}
  1155. X
  1156. XESCSEQ        \\([^\n]|[0-9]{1,3})
  1157. X
  1158. X%%
  1159. X    static int bracelevel, didadef;
  1160. X    int i, indented_code, checking_used;
  1161. X    char nmdef[MAXLINE], myesc();
  1162. X
  1163. X^{WS}            indented_code = true; BEGIN(CODEBLOCK);
  1164. X^#.*\n            ++linenum; ECHO; /* treat as a comment */
  1165. X^"/*"            ECHO; BEGIN(C_COMMENT);
  1166. X^"%s"(tart)?        return ( SCDECL );
  1167. X^"%x"            return ( XSCDECL );
  1168. X^"%{".*\n        {
  1169. X            ++linenum;
  1170. X            line_directive_out( stdout );
  1171. X            indented_code = false;
  1172. X            BEGIN(CODEBLOCK);
  1173. X            }
  1174. X
  1175. X{WS}            return ( WHITESPACE );
  1176. X
  1177. X^"%%".*            {
  1178. X            sectnum = 2;
  1179. X            line_directive_out( stdout );
  1180. X            BEGIN(SECT2PROLOG);
  1181. X            return ( SECTEND );
  1182. X            }
  1183. X
  1184. X^"%used"        checking_used = REALLY_USED; BEGIN(USED_LIST);
  1185. X^"%unused"        checking_used = REALLY_NOT_USED; BEGIN(USED_LIST);
  1186. X
  1187. X
  1188. X^"%"[^sx]" ".*\n        {
  1189. X            fprintf( stderr,
  1190. X                 "old-style lex command at line %d ignored:\n\t%s",
  1191. X                 linenum, yytext );
  1192. X            ++linenum;
  1193. X            }
  1194. X
  1195. X^{NAME}            {
  1196. X            (void) strcpy( nmstr, yytext );
  1197. X            didadef = false;
  1198. X            BEGIN(PICKUPDEF);
  1199. X            }
  1200. X
  1201. X{SCNAME}        RETURNNAME;
  1202. X^{OPTWS}\n        ++linenum; /* allows blank lines in section 1 */
  1203. X\n            ++linenum; return ( '\n' );
  1204. X.            synerr( "illegal character" ); BEGIN(RECOVER);
  1205. X
  1206. X
  1207. X<C_COMMENT>"*/"        ECHO; BEGIN(0);
  1208. X<C_COMMENT>"*/".*\n    ++linenum; ECHO; BEGIN(0);
  1209. X<C_COMMENT>[^*\n]+    ECHO;
  1210. X<C_COMMENT>"*"        ECHO;
  1211. X<C_COMMENT>\n        ++linenum; ECHO;
  1212. X
  1213. X
  1214. X<CODEBLOCK>^"%}".*\n    ++linenum; BEGIN(0);
  1215. X<CODEBLOCK>"reject"    ECHO; CHECK_REJECT(yytext);
  1216. X<CODEBLOCK>"yymore"    ECHO; CHECK_YYMORE(yytext);
  1217. X<CODEBLOCK>{NAME}|{NOT_NAME}|.    ECHO;
  1218. X<CODEBLOCK>\n        {
  1219. X            ++linenum;
  1220. X            ECHO;
  1221. X            if ( indented_code )
  1222. X                BEGIN(0);
  1223. X            }
  1224. X
  1225. X
  1226. X<PICKUPDEF>{WS}        /* separates name and definition */
  1227. X
  1228. X<PICKUPDEF>{NOT_WS}.*    {
  1229. X            (void) strcpy( nmdef, yytext );
  1230. X
  1231. X            for ( i = strlen( nmdef ) - 1;
  1232. X                  i >= 0 &&
  1233. X                  nmdef[i] == ' ' || nmdef[i] == '\t';
  1234. X                  --i )
  1235. X                ;
  1236. X
  1237. X            nmdef[i + 1] = '\0';
  1238. X
  1239. X                        ndinstal( nmstr, nmdef );
  1240. X            didadef = true;
  1241. X            }
  1242. X
  1243. X<PICKUPDEF>\n        {
  1244. X            if ( ! didadef )
  1245. X                synerr( "incomplete name definition" );
  1246. X            BEGIN(0);
  1247. X            ++linenum;
  1248. X            }
  1249. X
  1250. X<RECOVER>.*\n        ++linenum; BEGIN(0); RETURNNAME;
  1251. X
  1252. X
  1253. X<USED_LIST>\n        ++linenum; BEGIN(0);
  1254. X<USED_LIST>{WS}
  1255. X<USED_LIST>"reject"    {
  1256. X            if ( all_upper( yytext ) )
  1257. X                reject_really_used = checking_used;
  1258. X            else
  1259. X                synerr( "unrecognized %used/%unused construct" );
  1260. X            }
  1261. X<USED_LIST>"yymore"    {
  1262. X            if ( all_lower( yytext ) )
  1263. X                yymore_really_used = checking_used;
  1264. X            else
  1265. X                synerr( "unrecognized %used/%unused construct" );
  1266. X            }
  1267. X<USED_LIST>{NOT_WS}+    synerr( "unrecognized %used/%unused construct" );
  1268. X
  1269. X
  1270. X<SECT2PROLOG>.*\n/{NOT_WS}    {
  1271. X            ++linenum;
  1272. X            ACTION_ECHO;
  1273. X            MARK_END_OF_PROLOG;
  1274. X            BEGIN(SECT2);
  1275. X            }
  1276. X
  1277. X<SECT2PROLOG>.*\n    ++linenum; ACTION_ECHO;
  1278. X
  1279. X<SECT2PROLOG><<EOF>>    MARK_END_OF_PROLOG; yyterminate();
  1280. X
  1281. X<SECT2>^{OPTWS}\n    ++linenum; /* allow blank lines in section 2 */
  1282. X
  1283. X    /* this horrible mess of a rule matches indented lines which
  1284. X     * do not contain "/*".  We need to make the distinction because
  1285. X     * otherwise this rule will be taken instead of the rule which
  1286. X     * matches the beginning of comments like this one
  1287. X     */
  1288. X<SECT2>^{WS}([^/\n]|"/"[^*\n])*("/"?)\n    {
  1289. X            synerr( "indented code found outside of action" );
  1290. X            ++linenum;
  1291. X            }
  1292. X
  1293. X<SECT2>"<"        BEGIN(SC); return ( '<' );
  1294. X<SECT2>^"^"        return ( '^' );
  1295. X<SECT2>\"        BEGIN(QUOTE); return ( '"' );
  1296. X<SECT2>"{"/[0-9]        BEGIN(NUM); return ( '{' );
  1297. X<SECT2>"{"[^0-9\n][^}\n]*    BEGIN(BRACEERROR);
  1298. X<SECT2>"$"/[ \t\n]    return ( '$' );
  1299. X
  1300. X<SECT2>{WS}"%{"        {
  1301. X            bracelevel = 1;
  1302. X            BEGIN(PERCENT_BRACE_ACTION);
  1303. X            return ( '\n' );
  1304. X            }
  1305. X<SECT2>{WS}"|".*\n    continued_action = true; ++linenum; return ( '\n' );
  1306. X
  1307. X<SECT2>^{OPTWS}"/*"    ACTION_ECHO; BEGIN(C_COMMENT_2);
  1308. X
  1309. X<SECT2>{WS}        {
  1310. X            /* this rule is separate from the one below because
  1311. X             * otherwise we get variable trailing context, so
  1312. X             * we can't build the scanner using -{f,F}
  1313. X             */
  1314. X            bracelevel = 0;
  1315. X            continued_action = false;
  1316. X            BEGIN(ACTION);
  1317. X            return ( '\n' );
  1318. X            }
  1319. X
  1320. X<SECT2>{OPTWS}/\n    {
  1321. X            bracelevel = 0;
  1322. X            continued_action = false;
  1323. X            BEGIN(ACTION);
  1324. X            return ( '\n' );
  1325. X            }
  1326. X
  1327. X<SECT2>^{OPTWS}\n    ++linenum; return ( '\n' );
  1328. X
  1329. X<SECT2>"<<EOF>>"    return ( EOF_OP );
  1330. X
  1331. X<SECT2>^"%%".*        {
  1332. X            sectnum = 3;
  1333. X            BEGIN(SECT3);
  1334. X            return ( EOF ); /* to stop the parser */
  1335. X            }
  1336. X
  1337. X<SECT2>"["([^\\\]\n]|{ESCSEQ})+"]"    {
  1338. X            int cclval;
  1339. X
  1340. X            (void) strcpy( nmstr, yytext );
  1341. X
  1342. X            /* check to see if we've already encountered this ccl */
  1343. X            if ( (cclval = ccllookup( nmstr )) )
  1344. X                {
  1345. X                yylval = cclval;
  1346. X                ++cclreuse;
  1347. X                return ( PREVCCL );
  1348. X                }
  1349. X            else
  1350. X                {
  1351. X                /* we fudge a bit.  We know that this ccl will
  1352. X                 * soon be numbered as lastccl + 1 by cclinit
  1353. X                 */
  1354. X                cclinstal( nmstr, lastccl + 1 );
  1355. X
  1356. X                /* push back everything but the leading bracket
  1357. X                 * so the ccl can be rescanned
  1358. X                 */
  1359. X                PUT_BACK_STRING(nmstr, 1);
  1360. X
  1361. X                BEGIN(FIRSTCCL);
  1362. X                return ( '[' );
  1363. X                }
  1364. X            }
  1365. X
  1366. X<SECT2>"{"{NAME}"}"    {
  1367. X            register char *nmdefptr;
  1368. X            char *ndlookup();
  1369. X
  1370. X            (void) strcpy( nmstr, yytext );
  1371. X            nmstr[yyleng - 1] = '\0';  /* chop trailing brace */
  1372. X
  1373. X            /* lookup from "nmstr + 1" to chop leading brace */
  1374. X            if ( ! (nmdefptr = ndlookup( nmstr + 1 )) )
  1375. X                synerr( "undefined {name}" );
  1376. X
  1377. X            else
  1378. X                { /* push back name surrounded by ()'s */
  1379. X                unput(')');
  1380. X                PUT_BACK_STRING(nmdefptr, 0);
  1381. X                unput('(');
  1382. X                }
  1383. X            }
  1384. X
  1385. X<SECT2>[/|*+?.()]    return ( yytext[0] );
  1386. X<SECT2>.        RETURNCHAR;
  1387. X<SECT2>\n        ++linenum; return ( '\n' );
  1388. X
  1389. X
  1390. X<SC>","            return ( ',' );
  1391. X<SC>">"            BEGIN(SECT2); return ( '>' );
  1392. X<SC>">"/"^"        BEGIN(CARETISBOL); return ( '>' );
  1393. X<SC>{SCNAME}        RETURNNAME;
  1394. X<SC>.            synerr( "bad start condition name" );
  1395. X
  1396. X<CARETISBOL>"^"        BEGIN(SECT2); return ( '^' );
  1397. X
  1398. X
  1399. X<QUOTE>[^"\n]        RETURNCHAR;
  1400. X<QUOTE>\"        BEGIN(SECT2); return ( '"' );
  1401. X
  1402. X<QUOTE>\n        {
  1403. X            synerr( "missing quote" );
  1404. X            BEGIN(SECT2);
  1405. X            ++linenum;
  1406. X            return ( '"' );
  1407. X            }
  1408. X
  1409. X
  1410. X<FIRSTCCL>"^"/[^-\n]    BEGIN(CCL); return ( '^' );
  1411. X<FIRSTCCL>"^"/-        return ( '^' );
  1412. X<FIRSTCCL>-        BEGIN(CCL); yylval = '-'; return ( CHAR );
  1413. X<FIRSTCCL>.        BEGIN(CCL); RETURNCHAR;
  1414. X
  1415. X<CCL>-/[^\]\n]        return ( '-' );
  1416. X<CCL>[^\]\n]        RETURNCHAR;
  1417. X<CCL>"]"        BEGIN(SECT2); return ( ']' );
  1418. X
  1419. X
  1420. X<NUM>[0-9]+        {
  1421. X            yylval = myctoi( yytext );
  1422. X            return ( NUMBER );
  1423. X            }
  1424. X
  1425. X<NUM>","            return ( ',' );
  1426. X<NUM>"}"            BEGIN(SECT2); return ( '}' );
  1427. X
  1428. X<NUM>.            {
  1429. X            synerr( "bad character inside {}'s" );
  1430. X            BEGIN(SECT2);
  1431. X            return ( '}' );
  1432. X            }
  1433. X
  1434. X<NUM>\n            {
  1435. X            synerr( "missing }" );
  1436. X            BEGIN(SECT2);
  1437. X            ++linenum;
  1438. X            return ( '}' );
  1439. X            }
  1440. X
  1441. X
  1442. X<BRACEERROR>"}"        synerr( "bad name in {}'s" ); BEGIN(SECT2);
  1443. X<BRACEERROR>\n        synerr( "missing }" ); ++linenum; BEGIN(SECT2);
  1444. X
  1445. X
  1446. X<PERCENT_BRACE_ACTION>{OPTWS}"%}".*    bracelevel = 0;
  1447. X<PERCENT_BRACE_ACTION,ACTION>"reject"    ACTION_ECHO; CHECK_REJECT(yytext);
  1448. X<PERCENT_BRACE_ACTION,ACTION>"yymore"    ACTION_ECHO; CHECK_YYMORE(yytext);
  1449. X<PERCENT_BRACE_ACTION>{NAME}|{NOT_NAME}|.    ACTION_ECHO;
  1450. X<PERCENT_BRACE_ACTION>\n        {
  1451. X            ++linenum;
  1452. X            ACTION_ECHO;
  1453. X            if ( bracelevel == 0 )
  1454. X                {
  1455. X                fputs( "\tYY_BREAK\n", temp_action_file );
  1456. X                BEGIN(SECT2);
  1457. X                }
  1458. X            }
  1459. X
  1460. X    /* REJECT and yymore() are checked for above, in PERCENT_BRACE_ACTION */
  1461. X<ACTION>"{"        ACTION_ECHO; ++bracelevel;
  1462. X<ACTION>"}"        ACTION_ECHO; --bracelevel;
  1463. X<ACTION>[^a-z_{}"'/\n]+    ACTION_ECHO;
  1464. X<ACTION>{NAME}        ACTION_ECHO;
  1465. X<ACTION>"/*"        ACTION_ECHO; BEGIN(ACTION_COMMENT);
  1466. X<ACTION>"'"([^'\\\n]|\\.)*"'"    ACTION_ECHO; /* character constant */
  1467. X<ACTION>\"        ACTION_ECHO; BEGIN(ACTION_STRING);
  1468. X<ACTION>\n        {
  1469. X            ++linenum;
  1470. X            ACTION_ECHO;
  1471. X            if ( bracelevel == 0 )
  1472. X                {
  1473. X                fputs( "\tYY_BREAK\n", temp_action_file );
  1474. X                BEGIN(SECT2);
  1475. X                }
  1476. X            }
  1477. X<ACTION>.        ACTION_ECHO;
  1478. X
  1479. X<ACTION_COMMENT>"*/"    ACTION_ECHO; BEGIN(ACTION);
  1480. X<ACTION_COMMENT>[^*\n]+    ACTION_ECHO;
  1481. X<ACTION_COMMENT>"*"    ACTION_ECHO;
  1482. X<ACTION_COMMENT>\n    ++linenum; ACTION_ECHO;
  1483. X<ACTION_COMMENT>.    ACTION_ECHO;
  1484. X
  1485. X<C_COMMENT_2>"*/"    ACTION_ECHO; BEGIN(SECT2);
  1486. X<C_COMMENT_2>"*/".*\n    ++linenum; ACTION_ECHO; BEGIN(SECT2);
  1487. X<C_COMMENT_2>[^*\n]+    ACTION_ECHO;
  1488. X<C_COMMENT_2>"*"    ACTION_ECHO;
  1489. X<C_COMMENT_2>\n        ++linenum; ACTION_ECHO;
  1490. X
  1491. X<ACTION_STRING>[^"\\\n]+    ACTION_ECHO;
  1492. X<ACTION_STRING>\\.    ACTION_ECHO;
  1493. X<ACTION_STRING>\n    ++linenum; ACTION_ECHO;
  1494. X<ACTION_STRING>\"    ACTION_ECHO; BEGIN(ACTION);
  1495. X<ACTION_STRING>.    ACTION_ECHO;
  1496. X
  1497. X
  1498. X<SECT2,QUOTE,CCL>{ESCSEQ}    {
  1499. X            yylval = myesc( yytext );
  1500. X            return ( CHAR );
  1501. X            }
  1502. X
  1503. X<FIRSTCCL>{ESCSEQ}    {
  1504. X            yylval = myesc( yytext );
  1505. X            BEGIN(CCL);
  1506. X            return ( CHAR );
  1507. X            }
  1508. X
  1509. X
  1510. X<SECT3>.*(\n?)        ECHO;
  1511. X%%
  1512. END_OF_FILE
  1513. if test 10686 -ne `wc -c <'flex/scan.l'`; then
  1514.     echo shar: \"'flex/scan.l'\" unpacked with wrong size!
  1515. fi
  1516. # end of 'flex/scan.l'
  1517. fi
  1518. if test -f 'flex/sym.c' -a "${1}" != "-c" ; then 
  1519.   echo shar: Will not clobber existing file \"'flex/sym.c'\"
  1520. else
  1521. echo shar: Extracting \"'flex/sym.c'\" \(7259 characters\)
  1522. sed "s/^X//" >'flex/sym.c' <<'END_OF_FILE'
  1523. X/* sym - symbol table routines */
  1524. X
  1525. X/*
  1526. X * Copyright (c) 1989 The Regents of the University of California.
  1527. X * All rights reserved.
  1528. X *
  1529. X * This code is derived from software contributed to Berkeley by
  1530. X * Vern Paxson.
  1531. X * 
  1532. X * The United States Government has rights in this work pursuant to
  1533. X * contract no. DE-AC03-76SF00098 between the United States Department of
  1534. X * Energy and the University of California.
  1535. X *
  1536. X * Redistribution and use in source and binary forms are permitted
  1537. X * provided that the above copyright notice and this paragraph are
  1538. X * duplicated in all such forms and that any documentation,
  1539. X * advertising materials, and other materials related to such
  1540. X * distribution and use acknowledge that the software was developed
  1541. X * by the University of California, Berkeley.  The name of the
  1542. X * University may not be used to endorse or promote products derived
  1543. X * from this software without specific prior written permission.
  1544. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1545. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1546. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1547. X */
  1548. X
  1549. X#ifndef lint
  1550. X
  1551. Xstatic char copyright[] =
  1552. X    "@(#) Copyright (c) 1989 The Regents of the University of California.\n";
  1553. Xstatic char CR_continuation[] = "@(#) All rights reserved.\n";
  1554. X
  1555. Xstatic char rcsid[] =
  1556. X    "@(#) $Header: sym.c,v 2.0 89/06/20 15:50:17 vern Locked $ (LBL)";
  1557. X
  1558. X#endif
  1559. X
  1560. X#include "flexdef.h"
  1561. X
  1562. Xstruct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE];
  1563. Xstruct hash_entry *sctbl[START_COND_HASH_SIZE];
  1564. Xstruct hash_entry *ccltab[CCL_HASH_SIZE];
  1565. X
  1566. Xstruct hash_entry *findsym();
  1567. X
  1568. X
  1569. X/* addsym - add symbol and definitions to symbol table
  1570. X *
  1571. X * synopsis
  1572. X *    char sym[], *str_def;
  1573. X *    int int_def;
  1574. X *    hash_table table;
  1575. X *    int table_size;
  1576. X *    0 / -1 = addsym( sym, def, int_def, table, table_size );
  1577. X *
  1578. X * -1 is returned if the symbol already exists, and the change not made.
  1579. X */
  1580. X
  1581. Xint addsym( sym, str_def, int_def, table, table_size )
  1582. Xregister char sym[];
  1583. Xchar *str_def;
  1584. Xint int_def;
  1585. Xhash_table table;
  1586. Xint table_size;
  1587. X
  1588. X    {
  1589. X    int hash_val = hashfunct( sym, table_size );
  1590. X    register struct hash_entry *sym_entry = table[hash_val];
  1591. X    register struct hash_entry *new_entry;
  1592. X    register struct hash_entry *successor;
  1593. X    char *malloc();
  1594. X
  1595. X    while ( sym_entry )
  1596. X    {
  1597. X    if ( ! strcmp( sym, sym_entry->name ) )
  1598. X        { /* entry already exists */
  1599. X        return ( -1 );
  1600. X        }
  1601. X    
  1602. X    sym_entry = sym_entry->next;
  1603. X    }
  1604. X
  1605. X    /* create new entry */
  1606. X    new_entry = (struct hash_entry *) malloc( sizeof( struct hash_entry ) );
  1607. X
  1608. X    if ( new_entry == NULL )
  1609. X    flexfatal( "symbol table memory allocation failed" );
  1610. X
  1611. X    if ( (successor = table[hash_val]) )
  1612. X    {
  1613. X    new_entry->next = successor;
  1614. X    successor->prev = new_entry;
  1615. X    }
  1616. X    else
  1617. X    new_entry->next = NULL;
  1618. X
  1619. X    new_entry->prev = NULL;
  1620. X    new_entry->name = sym;
  1621. X    new_entry->str_val = str_def;
  1622. X    new_entry->int_val = int_def;
  1623. X
  1624. X    table[hash_val] = new_entry;
  1625. X
  1626. X    return ( 0 );
  1627. X    }
  1628. X
  1629. X
  1630. X/* cclinstal - save the text of a character class
  1631. X *
  1632. X * synopsis
  1633. X *    char ccltxt[];
  1634. X *    int cclnum;
  1635. X *    cclinstal( ccltxt, cclnum );
  1636. X */
  1637. X
  1638. Xcclinstal( ccltxt, cclnum )
  1639. Xchar ccltxt[];
  1640. Xint cclnum;
  1641. X
  1642. X    {
  1643. X    /* we don't bother checking the return status because we are not called
  1644. X     * unless the symbol is new
  1645. X     */
  1646. X    char *copy_string();
  1647. X
  1648. X    (void) addsym( copy_string( ccltxt ), (char *) 0, cclnum,
  1649. X           ccltab, CCL_HASH_SIZE );
  1650. X    }
  1651. X
  1652. X
  1653. X/* ccllookup - lookup the number associated with character class text
  1654. X *
  1655. X * synopsis
  1656. X *    char ccltxt[];
  1657. X *    int ccllookup, cclval;
  1658. X *    cclval/0 = ccllookup( ccltxt );
  1659. X */
  1660. X
  1661. Xint ccllookup( ccltxt )
  1662. Xchar ccltxt[];
  1663. X
  1664. X    {
  1665. X    return ( findsym( ccltxt, ccltab, CCL_HASH_SIZE )->int_val );
  1666. X    }
  1667. X
  1668. X
  1669. X/* findsym - find symbol in symbol table
  1670. X *
  1671. X * synopsis
  1672. X *    char sym[];
  1673. X *    hash_table table;
  1674. X *    int table_size;
  1675. X *    struct hash_entry *sym_entry, *findsym();
  1676. X *    sym_entry = findsym( sym, table, table_size );
  1677. X */
  1678. X
  1679. Xstruct hash_entry *findsym( sym, table, table_size )
  1680. Xregister char sym[];
  1681. Xhash_table table;
  1682. Xint table_size;
  1683. X
  1684. X    {
  1685. X    register struct hash_entry *sym_entry = table[hashfunct( sym, table_size )];
  1686. X    static struct hash_entry empty_entry =
  1687. X    {
  1688. X    (struct hash_entry *) 0, (struct hash_entry *) 0, NULL, NULL, 0,
  1689. X    } ;
  1690. X
  1691. X    while ( sym_entry )
  1692. X    {
  1693. X    if ( ! strcmp( sym, sym_entry->name ) )
  1694. X        return ( sym_entry );
  1695. X    sym_entry = sym_entry->next;
  1696. X    }
  1697. X
  1698. X    return ( &empty_entry );
  1699. X    }
  1700. X
  1701. X    
  1702. X/* hashfunct - compute the hash value for "str" and hash size "hash_size"
  1703. X *
  1704. X * synopsis
  1705. X *    char str[];
  1706. X *    int hash_size, hash_val;
  1707. X *    hash_val = hashfunct( str, hash_size );
  1708. X */
  1709. X
  1710. Xint hashfunct( str, hash_size )
  1711. Xregister char str[];
  1712. Xint hash_size;
  1713. X
  1714. X    {
  1715. X    register int hashval;
  1716. X    register int locstr;
  1717. X
  1718. X    hashval = 0;
  1719. X    locstr = 0;
  1720. X
  1721. X    while ( str[locstr] )
  1722. X    hashval = ((hashval << 1) + str[locstr++]) % hash_size;
  1723. X
  1724. X    return ( hashval );
  1725. X    }
  1726. X
  1727. X
  1728. X/* ndinstal - install a name definition
  1729. X *
  1730. X * synopsis
  1731. X *    char nd[], def[];
  1732. X *    ndinstal( nd, def );
  1733. X */
  1734. X
  1735. Xndinstal( nd, def )
  1736. Xchar nd[], def[];
  1737. X
  1738. X    {
  1739. X    char *copy_string();
  1740. X
  1741. X    if ( addsym( copy_string( nd ), copy_string( def ), 0,
  1742. X         ndtbl, NAME_TABLE_HASH_SIZE ) )
  1743. X    synerr( "name defined twice" );
  1744. X    }
  1745. X
  1746. X
  1747. X/* ndlookup - lookup a name definition
  1748. X *
  1749. X * synopsis
  1750. X *    char nd[], *def;
  1751. X *    char *ndlookup();
  1752. X *    def/NULL = ndlookup( nd );
  1753. X */
  1754. X
  1755. Xchar *ndlookup( nd )
  1756. Xchar nd[];
  1757. X
  1758. X    {
  1759. X    return ( findsym( nd, ndtbl, NAME_TABLE_HASH_SIZE )->str_val );
  1760. X    }
  1761. X
  1762. X
  1763. X/* scinstal - make a start condition
  1764. X *
  1765. X * synopsis
  1766. X *    char str[];
  1767. X *    int xcluflg;
  1768. X *    scinstal( str, xcluflg );
  1769. X *
  1770. X * NOTE
  1771. X *    the start condition is Exclusive if xcluflg is true
  1772. X */
  1773. X
  1774. Xscinstal( str, xcluflg )
  1775. Xchar str[];
  1776. Xint xcluflg;
  1777. X
  1778. X    {
  1779. X    char *copy_string();
  1780. X
  1781. X    /* bit of a hack.  We know how the default start-condition is
  1782. X     * declared, and don't put out a define for it, because it
  1783. X     * would come out as "#define 0 1"
  1784. X     */
  1785. X    /* actually, this is no longer the case.  The default start-condition
  1786. X     * is now called "INITIAL".  But we keep the following for the sake
  1787. X     * of future robustness.
  1788. X     */
  1789. X
  1790. X    if ( strcmp( str, "0" ) )
  1791. X    printf( "#define %s %d\n", str, lastsc );
  1792. X
  1793. X    if ( ++lastsc >= current_max_scs )
  1794. X    {
  1795. X    current_max_scs += MAX_SCS_INCREMENT;
  1796. X
  1797. X    ++num_reallocs;
  1798. X
  1799. X    scset = reallocate_integer_array( scset, current_max_scs );
  1800. X    scbol = reallocate_integer_array( scbol, current_max_scs );
  1801. X    scxclu = reallocate_integer_array( scxclu, current_max_scs );
  1802. X    sceof = reallocate_integer_array( sceof, current_max_scs );
  1803. X    scname = reallocate_char_ptr_array( scname, current_max_scs );
  1804. X    actvsc = reallocate_integer_array( actvsc, current_max_scs );
  1805. X    }
  1806. X
  1807. X    scname[lastsc] = copy_string( str );
  1808. X
  1809. X    if ( addsym( scname[lastsc], (char *) 0, lastsc,
  1810. X         sctbl, START_COND_HASH_SIZE ) )
  1811. X    lerrsf( "start condition %s declared twice", str );
  1812. X
  1813. X    scset[lastsc] = mkstate( SYM_EPSILON );
  1814. X    scbol[lastsc] = mkstate( SYM_EPSILON );
  1815. X    scxclu[lastsc] = xcluflg;
  1816. X    sceof[lastsc] = false;
  1817. X    }
  1818. X
  1819. X
  1820. X/* sclookup - lookup the number associated with a start condition
  1821. X *
  1822. X * synopsis
  1823. X *    char str[], scnum;
  1824. X *    int sclookup;
  1825. X *    scnum/0 = sclookup( str );
  1826. X */
  1827. X
  1828. Xint sclookup( str )
  1829. Xchar str[];
  1830. X
  1831. X    {
  1832. X    return ( findsym( str, sctbl, START_COND_HASH_SIZE )->int_val );
  1833. X    }
  1834. END_OF_FILE
  1835. if test 7259 -ne `wc -c <'flex/sym.c'`; then
  1836.     echo shar: \"'flex/sym.c'\" unpacked with wrong size!
  1837. fi
  1838. # end of 'flex/sym.c'
  1839. fi
  1840. if test -f 'flex/yylex.c' -a "${1}" != "-c" ; then 
  1841.   echo shar: Will not clobber existing file \"'flex/yylex.c'\"
  1842. else
  1843. echo shar: Extracting \"'flex/yylex.c'\" \(4412 characters\)
  1844. sed "s/^X//" >'flex/yylex.c' <<'END_OF_FILE'
  1845. X/* yylex - scanner front-end for flex */
  1846. X
  1847. X/*
  1848. X * Copyright (c) 1989 The Regents of the University of California.
  1849. X * All rights reserved.
  1850. X *
  1851. X * This code is derived from software contributed to Berkeley by
  1852. X * Vern Paxson.
  1853. X * 
  1854. X * The United States Government has rights in this work pursuant to
  1855. X * contract no. DE-AC03-76SF00098 between the United States Department of
  1856. X * Energy and the University of California.
  1857. X *
  1858. X * Redistribution and use in source and binary forms are permitted
  1859. X * provided that the above copyright notice and this paragraph are
  1860. X * duplicated in all such forms and that any documentation,
  1861. X * advertising materials, and other materials related to such
  1862. X * distribution and use acknowledge that the software was developed
  1863. X * by the University of California, Berkeley.  The name of the
  1864. X * University may not be used to endorse or promote products derived
  1865. X * from this software without specific prior written permission.
  1866. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  1867. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  1868. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1869. X */
  1870. X
  1871. X#ifndef lint
  1872. X
  1873. Xstatic char copyright[] =
  1874. X    "@(#) Copyright (c) 1989 The Regents of the University of California.\n";
  1875. Xstatic char CR_continuation[] = "@(#) All rights reserved.\n";
  1876. X
  1877. Xstatic char rcsid[] =
  1878. X    "@(#) $Header: yylex.c,v 2.0 89/06/20 15:50:28 vern Locked $ (LBL)";
  1879. X
  1880. X#endif
  1881. X
  1882. X#include "flexdef.h"
  1883. X#include "parse.h"
  1884. X
  1885. X/* yylex - scan for a regular expression token
  1886. X *
  1887. X * synopsis
  1888. X *
  1889. X *   token = yylex();
  1890. X *
  1891. X *     token - return token found
  1892. X */
  1893. X
  1894. Xint yylex()
  1895. X
  1896. X    {
  1897. X    int toktype;
  1898. X    static int beglin = false;
  1899. X
  1900. X    if ( eofseen )
  1901. X    toktype = EOF;
  1902. X    else
  1903. X    toktype = flexscan();
  1904. X
  1905. X    if ( toktype == EOF )
  1906. X    {
  1907. X    eofseen = 1;
  1908. X
  1909. X    if ( sectnum == 1 )
  1910. X        {
  1911. X        synerr( "unexpected EOF" );
  1912. X        sectnum = 2;
  1913. X        toktype = SECTEND;
  1914. X        }
  1915. X
  1916. X    else if ( sectnum == 2 )
  1917. X        {
  1918. X        sectnum = 3;
  1919. X        toktype = SECTEND;
  1920. X        }
  1921. X
  1922. X    else
  1923. X        toktype = 0;
  1924. X    }
  1925. X
  1926. X    if ( trace )
  1927. X    {
  1928. X    if ( beglin )
  1929. X        {
  1930. X        fprintf( stderr, "%d\t", num_rules + 1 );
  1931. X        beglin = 0;
  1932. X        }
  1933. X
  1934. X    switch ( toktype )
  1935. X        {
  1936. X        case '<':
  1937. X        case '>':
  1938. X        case '^':
  1939. X        case '$':
  1940. X        case '"':
  1941. X        case '[':
  1942. X        case ']':
  1943. X        case '{':
  1944. X        case '}':
  1945. X        case '|':
  1946. X        case '(':
  1947. X        case ')':
  1948. X        case '-':
  1949. X        case '/':
  1950. X        case '\\':
  1951. X        case '?':
  1952. X        case '.':
  1953. X        case '*':
  1954. X        case '+':
  1955. X        case ',':
  1956. X        (void) putc( toktype, stderr );
  1957. X        break;
  1958. X
  1959. X        case '\n':
  1960. X        (void) putc( '\n', stderr );
  1961. X
  1962. X        if ( sectnum == 2 )
  1963. X            beglin = 1;
  1964. X
  1965. X        break;
  1966. X
  1967. X        case SCDECL:
  1968. X        fputs( "%s", stderr );
  1969. X        break;
  1970. X
  1971. X        case XSCDECL:
  1972. X        fputs( "%x", stderr );
  1973. X        break;
  1974. X
  1975. X        case WHITESPACE:
  1976. X        (void) putc( ' ', stderr );
  1977. X        break;
  1978. X
  1979. X        case SECTEND:
  1980. X        fputs( "%%\n", stderr );
  1981. X
  1982. X        /* we set beglin to be true so we'll start
  1983. X         * writing out numbers as we echo rules.  flexscan() has
  1984. X         * already assigned sectnum
  1985. X         */
  1986. X
  1987. X        if ( sectnum == 2 )
  1988. X            beglin = 1;
  1989. X
  1990. X        break;
  1991. X
  1992. X        case NAME:
  1993. X        fprintf( stderr, "'%s'", nmstr );
  1994. X        break;
  1995. X
  1996. X        case CHAR:
  1997. X        switch ( yylval )
  1998. X            {
  1999. X            case '<':
  2000. X            case '>':
  2001. X            case '^':
  2002. X            case '$':
  2003. X            case '"':
  2004. X            case '[':
  2005. X            case ']':
  2006. X            case '{':
  2007. X            case '}':
  2008. X            case '|':
  2009. X            case '(':
  2010. X            case ')':
  2011. X            case '-':
  2012. X            case '/':
  2013. X            case '\\':
  2014. X            case '?':
  2015. X            case '.':
  2016. X            case '*':
  2017. X            case '+':
  2018. X            case ',':
  2019. X            fprintf( stderr, "\\%c", yylval );
  2020. X            break;
  2021. X
  2022. X            case 1:
  2023. X            case 2:
  2024. X            case 3:
  2025. X            case 4:
  2026. X            case 5:
  2027. X            case 6:
  2028. X            case 7:
  2029. X            case 8:
  2030. X            case 9:
  2031. X            case 10:
  2032. X            case 11:
  2033. X            case 12:
  2034. X            case 13:
  2035. X            case 14:
  2036. X            case 15:
  2037. X            case 16:
  2038. X            case 17:
  2039. X            case 18:
  2040. X            case 19:
  2041. X            case 20:
  2042. X            case 21:
  2043. X            case 22:
  2044. X            case 23:
  2045. X            case 24:
  2046. X            case 25:
  2047. X            case 26:
  2048. X            case 27:
  2049. X            case 28:
  2050. X            case 29:
  2051. X            case 30:
  2052. X            case 31:
  2053. X            case 127:
  2054. X            fprintf( stderr, "\\%.3o", yylval );
  2055. X            break;
  2056. X
  2057. X            default:
  2058. X            (void) putc( yylval, stderr );
  2059. X            break;
  2060. X            }
  2061. X            
  2062. X        break;
  2063. X
  2064. X        case NUMBER:
  2065. X        fprintf( stderr, "%d", yylval );
  2066. X        break;
  2067. X
  2068. X        case PREVCCL:
  2069. X        fprintf( stderr, "[%d]", yylval );
  2070. X        break;
  2071. X
  2072. X        case 0:
  2073. X        fprintf( stderr, "End Marker" );
  2074. X        break;
  2075. X
  2076. X        default:
  2077. X        fprintf( stderr, "*Something Weird* - tok: %d val: %d\n",
  2078. X             toktype, yylval );
  2079. X        break;
  2080. X        }
  2081. X    }
  2082. X        
  2083. X    return ( toktype );
  2084. X    }
  2085. END_OF_FILE
  2086. if test 4412 -ne `wc -c <'flex/yylex.c'`; then
  2087.     echo shar: \"'flex/yylex.c'\" unpacked with wrong size!
  2088. fi
  2089. # end of 'flex/yylex.c'
  2090. fi
  2091. echo shar: End of archive 1 \(of 7\).
  2092. cp /dev/null ark1isdone
  2093. MISSING=""
  2094. for I in 1 2 3 4 5 6 7 ; do
  2095.     if test ! -f ark${I}isdone ; then
  2096.     MISSING="${MISSING} ${I}"
  2097.     fi
  2098. done
  2099. if test "${MISSING}" = "" ; then
  2100.     echo You have unpacked all 7 archives.
  2101.     rm -f ark[1-9]isdone
  2102. else
  2103.     echo You still need to unpack the following archives:
  2104.     echo "        " ${MISSING}
  2105. fi
  2106. ##  End of shell archive.
  2107. exit 0
  2108.